<?php

    class Messages{

        private $key = '_messages';
        
        function set($name, $message){
            if(count($_SESSION[$this->key]) == 0):
                $_SESSION[$this->key] = array();
            endif;
            
           $_SESSION[$this->key][$name][] = $message;
        }
        
        function get($name){
            $message = $_SESSION[$this->key][$name];
            unset($_SESSION[$this->key][$name]);
            return $message;
        }
        
        function all(){
            $messages = $_SESSION [$this->key];
            unset($_SESSION[$this->key]);
            return $messages;
        }
    }
    
    
function test(){
    session_start();
    $db = $_SESSION['db'];
    return $db;
}

function in_array_field($needle, $needle_field, $haystack, $strict = false) {
    if ($strict) {
        foreach ($haystack as $item)
            if (isset($item->$needle_field) && $item->$needle_field === $needle)
                return true;
    }
    else {
        foreach ($haystack as $item)
            if (isset($item->$needle_field) && $item->$needle_field == $needle)
                return true;
    }
    return false;
} 

?>
